package com.rachel.studyapp.mvp.present;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.rachel.studyapp.entries.UserInfo;
import com.rachel.studyapp.mvp.ContractUtils;
import com.rachel.studyapp.mvp.base.BasePresent;
import com.rachel.studyapp.mvp.model.MineModel;

/**
 * Created by zhengshaorui on 2017/8/29.
 */

public class MinePresent extends BasePresent<ContractUtils.IMineView>
                implements ContractUtils.IMinePresent{

    private ContractUtils.IMineView mView;
    private MineModel mModel;
    Handler mHandler = new Handler(Looper.getMainLooper());

    public MinePresent(ContractUtils.IMineView view, Context context) {
        mView = view;
        mModel = new MineModel(this);

    }




    @Override
    public void onCreatePresent() {

    }

    @Override
    public void onFailure(Object errorObj) {

    }


    public void login(UserInfo userInfo) {
        mModel.login(userInfo);
    }


    public void register(UserInfo userInfo) {
        mModel.register(userInfo);
    }

    @Override
    public void loginSuccess(final UserInfo info) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mView.loginSuccess(info);
            }
        });
    }

    @Override
    public void loginFailure(final Object errorObj) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mView.loginFailure(errorObj);
            }
        });
    }

    @Override
    public void registerSuccess(final UserInfo info) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mView.registerSuccess(info);
            }
        });
    }

    @Override
    public void registerFailure(final Object errorObj) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mView.registerFailure(errorObj);
            }
        });
    }

    @Override
    public void showloading() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mView.showloading();
            }
        });
    }

    @Override
    public void hideloading() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mView.hideloading();
            }
        });
    }
}
